/**
 * 作者：陈文斌 on 2019/1/21.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/VisitorRecord/visitor_record_model.dart';

class VisitorRecordListRow extends StatelessWidget {
  final VisitorRecordModel visitorRecord;
  final VoidCallback onTap;

  VisitorRecordListRow({Key key, this.visitorRecord, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget _infoSection({@required String name, @required String visitType}) {
      return Container(
        height: 25,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Expanded(
              child: Text(
                name,
                style: TextStyle(
                  color: AppColors.TextColor,
                  fontSize: AppFontSizes.Font15,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w700,
                ),
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
              ),
            ),
            Container(
              height: 20,
              constraints: BoxConstraints(
                minWidth: 60,
              ),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                gradient: LinearGradient(
                  colors: [
                    Color(0xFF67B9FF),
                    Color(0xFF408AFF),
                  ],
                ),
              ),
              padding: EdgeInsets.fromLTRB(12, 3.5, 12, 3.5),
              child: Text(
                visitType,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 9,
                ),
              ),
            ),
          ],
        ),
      );
    }

    Widget _issueInfoSection({String date, String time, String address}) {
      return Container(
        height: 16,
        margin: EdgeInsets.fromLTRB(0, 5, 0, 8),
        child: Row(
          children: <Widget>[
            Container(
              child: Text(
                date,
                style: TextStyle(
                  color: AppColors.MainColor,
                  fontSize: 11,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(
                right: AppScreen.setWidth(38),
              ),
            ),
            Container(
              child: Text(
                time,
                style: TextStyle(
                  color: AppColors.MainColor,
                  fontSize: 11,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(
                right: AppScreen.setWidth(38),
              ),
            ),
            Expanded(
              child: Text(
                address,
                style: TextStyle(
                  color: AppColors.MainColor,
                  fontSize: 11,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w500,
                ),
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
              ),
            )
          ],
        ),
      );
    }

    Widget _contentSection({String content}) {
      return Container(
        constraints: BoxConstraints(
          maxHeight: 44,
        ),
        child: Text(
          content,
          style: TextStyle(
            color: AppColors.TextColor,
            fontSize: AppFontSizes.Font14,
            fontFamily: AppFontFamilies.PingFangSC,
            fontWeight: FontWeight.w500,
          ),
          overflow: TextOverflow.ellipsis,
          maxLines: 2,
        ),
      );
    }

    Widget _imagesListSection({List<String> imagesUrl}) {
      imagesUrl ??= List<String>();

      return Offstage(
        offstage: imagesUrl.length == 0,
        child: Container(
          child: GridView.count(
            shrinkWrap: true,
            primary: false,
            crossAxisCount: 7,
            children: imagesUrl.map((imageUrl) {
              return Container();
            }).toList(),
          ),
        ),
      );
    }

    Widget _locationSection({String location}) {
      return Container(
        height: 18,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              'images/bt_chat_location.png',
              width: 18,
              height: 18,
              fit: BoxFit.fill,
            ),
            Padding(padding: EdgeInsets.only(right: 8)),
            Expanded(
              child: Text(
                '信兴拉链',
                style: TextStyle(
                  color: AppColors.DetailTextColor,
                  fontSize: AppFontSizes.Font13,
                  fontFamily: AppFontFamilies.PingFangSC,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
          ],
        ),
      );
    }

    return Material(
      color: Colors.white,
      child: InkWell(
        onTap: onTap,
        child: Padding(
          padding: EdgeInsets.fromLTRB(
            AppScreen.setWidth(16),
            10,
            AppScreen.setWidth(16),
            10,
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              _infoSection(
                name: visitorRecord.visitorEmployeeId ?? '',
                visitType: visitorRecord.visitorType ?? '',
              ),
              _issueInfoSection(
                date: '2019-1-1',
                time: '12:00',
                address: visitorRecord.visitorAddress ?? '',
              ),
              Divider(
                height: 1,
                color: AppColors.LineColor,
              ),
              Padding(padding: EdgeInsets.only(top: 12)),
              _contentSection(content: visitorRecord.visitorDetails ?? ''),
              _imagesListSection(),
              Padding(padding: EdgeInsets.only(top: 8)),
              _locationSection(location: '新兴拉链'),
            ],
          ),
        ),
      ),
    );
  }
}
